<template>
  <div>
    <business-form
      :formDateObj="formDateObj"
      :formData="formData"
      :formDataText="formDataText"
    ></business-form>
    <div class="btn" style="background-color: white; margin-top: 20px">
      <a @click="countChange()">全部{{ Count }}</a>
      <a @click="countChange(1)">新建{{ count[1] }}</a>
      <a @click="countChange(2)">已装车{{ count[2] }}</a>
      <a @click="countChange(3)">运输中{{ count[3] }}</a>
      <a @click="countChange(4)">到达终端网点{{ count[4] }}</a>
      <a @click="countChange(6)">拒收{{ count[6] }}</a>
    </div>
    <el-row style="margin-top: 20px">
      <el-card>
        <el-col>
          <el-table
            border
            stripe
            style="text-align: center; margin-top: 15px; margin-bottom: 20px"
            :data="tableDate"
          >
            <template slot="empty">
              <img
                height="270px"
                src="https://slwl-admin.itheima.net/static/img/pic-kong.742d3899.png"
                alt=""
                srcset=""
              />
            </template>
            <el-table-column
              type="index"
              width="50"
              label="序号"
            ></el-table-column>
            <el-table-column
              width="190"
              prop="id"
              label="运单编号"
            ></el-table-column>
            <el-table-column
              prop="orderId"
              width="200"
              label="订单编号"
            ></el-table-column>
            <el-table-column width="160" prop="status" label="运单状态">
              <template #default="{ row }">
                {{ DivMap[row.status] }}
              </template>
            </el-table-column>
            <el-table-column
              prop="schedulingStatus"
              width="160"
              label="调度状态"
            >
              <template #default="{ row }">
                {{
                  row.schedulingStatus === 1
                    ? "待调度"
                    : row.schedulingStatus === 2
                    ? "未匹配路线"
                    : "已调度"
                }}
              </template>
            </el-table-column>
            <el-table-column
              prop="startAgencyName"
              width="160"
              label="起始营业部"
            >
            </el-table-column>
            <el-table-column
              prop="endAgencyName"
              width="160"
              label="终点营业部"
            >
            </el-table-column>
            <el-table-column
              prop="currentAgencyName"
              width="160"
              label="当前所在机构"
            >
            </el-table-column>
            <el-table-column
              prop="nextAgencyName"
              width="160"
              label="下一个机构"
            >
            </el-table-column>
            <el-table-column
              prop="totalVolume"
              width="180"
              label="货品总体积（立方米）"
            >
            </el-table-column>
            <el-table-column
              prop="totalWeight"
              width="160"
              label="货品总重量（千克）"
            ></el-table-column>
            <el-table-column prop="created" width="160" label="创建时间">
            </el-table-column>
            <el-table-column prop="updated" width="160" label="更新时间">
            </el-table-column>
            <el-table-column prop="" label="操作" fixed="right" width="140">
              <template #default="{ row }">
                <el-button
                  @click="tiao(row.id)"
                  style="color: deepskyblue"
                  type="text"
                  >查看详情</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            style="margin-bottom: 20px"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="this.page.page"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="this.page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </el-col>
      </el-card>
    </el-row>
  </div>
</template>

<script>
import { getYunDanListApi, getYunNumber } from "@/api/business";
import BusinessForm from "@/components/businessForm.vue";

export default {
  components: { BusinessForm },
  data() {
    return {
      formDateObj: {
        schedulingStatus: "",
        orderId: "",
        id: "",
        startAgencyId: "",
        endAgencyId: "",
        currentAgencyId: "",
      },
      formData: [
        { schedulingStatus: "" },
        { orderId: "" },
        { id: "" },
        { startAgencyId: "" },
        { endAgencyId: "" },
        { currentAgencyId: "" },
      ],
      formDataText: [
        {
          labels: "调度状态:",
          text: "请输入调度状态",
        },
        {
          labels: "订单编号:",
          text: "请输入订单编号",
        },
        {
          labels: "运单编号:",
          text: "请输入运单编号",
        },
        {
          labels: "起始地机构:",
          text: "请输入起始地机构",
        },
        {
          labels: "目的地机构:",
          text: "请输入目的地机构",
        },
        {
          labels: "当前所在机构:",
          text: "请输入当前所在机构",
        },
      ],
      DivMap: {
        1: "新建",
        2: "已装车",
        3: "运输中",
        4: "到达终端网点",
        6: "拒收",
      },
      page: {
        page: 1,
        pageSize: 10,
      },
      count: {},
      total: 100,
      tableDate: [],
    };
  },
  computed: {
    Count() {
      return (
        +this.count[1] +
        +this.count[2] +
        +this.count[3] +
        +this.count[4] +
        +this.count[6]
      );
    },
  },
  created() {
    this.getYunDanListInfo();
  },
  methods: {
    tiao(id) {
      console.log(id);
      this.$router.push(`/yundanXiangqing/${id}`);
    },
    async countChange(num) {
      const status = num;
      const res = await getYunDanListApi({ ...this.page, status });
      this.tableDate = res.data.data.items;
      this.total = +res.data.data.counts;
    },
    async getYunDanListInfo() {
      const res = await getYunDanListApi(this.page);
      const res1 = await getYunNumber();
      console.log(res.data.data);
      this.tableDate = res.data.data.items;
      this.total = +res.data.data.counts;
      this.count = res1.data.data;
      // console.log(res1);
    },
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.getYunDanListInfo();
    },
    handleCurrentChange(val) {
      this.page.page = val;
      this.getYunDanListInfo();
    },
  },
};
</script>

<style lang="scss" scoped>
.btn {
  border-radius: 4px;
  height: 50px;
  a {
    display: inline-block;
    height: 50px;
    line-height: 50px;
    text-align: center;
    width: 120px;
    color: black;
    float: left;
  }
  a:active {
    background-color: rgb(255, 238, 235);
    color: rgb(225, 85, 54);
  }
}
.el-pagination {
  text-align: center;
}
</style>
